package cn.supermarket.utils;



import org.springframework.stereotype.Component;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

@Component
public class GetDateTime {
    /**
     * 获取某一天的起点00：00
     * @param dateStart
     * @return
     */
    public LocalDateTime getDateStart( Date dateStart) {
        ZoneId zoneId = ZoneId.systemDefault();
        //获取起始日期的0点
        Instant startInstant = dateStart.toInstant();
        LocalDate localDateStart = startInstant.atZone(zoneId).toLocalDate();
        LocalDateTime start = localDateStart.atStartOfDay();
        return start;
    }

    /**
     * 获取某一天的最后一刻24：00
     * @param dateEnd
     * @return
     */
    public LocalDateTime getDateEnd( Date dateEnd) {
        ZoneId zoneId = ZoneId.systemDefault();

        //获取截止日期的0点
        Instant endInstant = dateEnd.toInstant();
        LocalDate localDateEnd = endInstant.atZone(zoneId).toLocalDate();
        LocalDateTime end = localDateEnd.atStartOfDay().plusDays(1);
        return end;
    }
}
